package ystp.controller;

import jxl.Workbook;
import jxl.format.UnderlineStyle;
import jxl.write.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ystp.model.*;
import ystp.service.ShengchanqiyelinxuanService;
import ystp.service.ShengchanqiyelinxuanzhongjianjieguoService;
import ystp.service.YsrenyuanfenpeiService;
import ystp.service.YsuserService;
import ystp.model.*;
import ystp.service.*;
import ystp.support.JsonResult;
import ystp.support.PageInfo;
import ystp.support.StringHandle;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

@RestController
@RequestMapping("shengchanqiye")
public class ShengchanqiyelinxuanController {
    @Resource
    ShengchanqiyelinxuanService ddService;

    @Resource
    ShengchanqiyelinxuantoupiaoService ddShengchanqiyelinxuantoupiaoService;

    @Resource
    YsrenyuanfenpeiService ddYsrenyuanfenpeiService;

    @Resource
    YsuserService ddYsuserService;

    @Resource
    public YsxiangmuService ddYsxiangmuService;

    @Resource
    ShengchanqiyelinxuanzhongjianjieguoService ddShengchanqiyelinxuanzhongjianjieguoService;

    public Logger log = LoggerFactory.getLogger(ShengchanqiyelinxuanController.class);

    public String mmsuijilunci="";

    @RequestMapping("getjindulist")
    public JsonResult<?> getjindulist(@RequestParam("xiangmuid") String ppxiangmuId){
        try{
            List<Map<String,Object>> mmJindulist = new ArrayList<>();
            Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppxiangmuId);
            int mmLunci = mmYsxiangmu.getLunci();
            List<Map<String, Object>> mmUserList=ddYsrenyuanfenpeiService.findRenyuanFenpeiByXiangmuId(ppxiangmuId);
            for(Map<String, Object> ysrenyuanfenpei:mmUserList){
                Map<String, Object> mmMap = new HashMap<String, Object>();
                String mmUserId=ysrenyuanfenpei.get("userid").toString();
                Ysuser mmYsuser=ddYsuserService.findOne(mmUserId);
                String mmUserName=mmYsuser.getUsername();

                int mmPass = ddShengchanqiyelinxuantoupiaoService.countPass(ppxiangmuId,mmUserId);
                int mmtotalshu = ddService.countTotal(ppxiangmuId,mmUserId,mmLunci);
                int mmJicaiPass = ddShengchanqiyelinxuantoupiaoService.countJicaiPass(ppxiangmuId,mmUserId);
                int mmJicaishu = ddService.countJicai(ppxiangmuId);

                String mmShifoutijiao="";
                if("1".equals(ysrenyuanfenpei.get("issubmit").toString())){
                    mmShifoutijiao="是";
                }else {
                    mmShifoutijiao="否";
                }

                mmMap.put("username", mmUserName);
                mmMap.put("shengchanqiyeshu", mmPass+"/"+mmtotalshu);
                mmMap.put("jicaishu", mmJicaiPass+"/"+mmJicaishu);
                mmMap.put("shifoutijiao", mmShifoutijiao);
                mmJindulist.add(mmMap);

            }
            return JsonResult.getSuccessResult(mmJindulist);

        }catch (Exception e) {
            e.printStackTrace();
            log.error("tongkeyaopin/getjindulist:error",e);
            return JsonResult.getErrorResult("tongkeyaopin/getjindulist:error " + e.getMessage());
        }
    }

    @RequestMapping("delete")
    public JsonResult<?> delete(@RequestParam("xiangmuid") String ppxiangmuId){
        try {

            return ddService.deleteByxiangmuId(ppxiangmuId)==true? JsonResult.getSuccessResult("删除材料成功")
                    : JsonResult.getErrorResult("删除材料失败");

        }catch (Exception e) {
            e.printStackTrace();
            log.error("shengchanqiye/delete:error",e);
            return JsonResult.getErrorResult("shengchanqiye/delete:error " + e.getMessage());
        }
    }

    @RequestMapping("randomsmpling")
    public JsonResult<?> randomsmpling(){
        try {

            smpling();

            return JsonResult.getSuccessResult("抽取成功");
        }catch (Exception e) {
            e.printStackTrace();
            log.error("shengchanqiye/randomsmpling:error",e);
            return JsonResult.getErrorResult("shengchanqiye/randomsmpling:error " + e.getMessage());
        }
    }

    @RequestMapping("findBiaojuelist")
    public JsonResult<?> findBiaojuelist(@RequestParam("xiangmuid") String ppxiangmuId,
                                         @RequestParam("userid")String ppuserId,
                                         @RequestParam("lunci")int pplunci,
                                         @RequestParam("guigexuhao")String ppGuigexuhao,
                                         @RequestParam("drugname")String ppDrugname,
                                         @RequestParam("jiyao")String ppJiyao,
                                         @RequestParam("jicaiyao")String ppJicaiyao,
                                         @RequestParam("pageindex") int ppPageIndex,
                                         @RequestParam("pagesize") int ppPageSize){
        try {
            List<Map<String,Object>> mmShengchanList = new ArrayList<>();
            List<Map<String,Object>> mmPinzhongAll = ddService.findPinzhong(ppxiangmuId,pplunci,ppDrugname,ppGuigexuhao,ppJiyao,ppJicaiyao,ppPageIndex,ppPageSize);

            for (int i = 0; i < mmPinzhongAll.size(); i++) {
                int mmPinzhongHebingshu = 0;
                Map<String,Object> mmMap = mmPinzhongAll.get(i);
                if (mmMap!=null){
                    List<Map<String,Object>> mmPinguiList = new ArrayList<>();
                    String mmPinzhongOne = mmMap.get("pinzhongbianhao") == null ? "" : mmMap.get("pinzhongbianhao").toString();
                    List<Map<String,Object>> mmPinguilist = ddService.findPinguiByPinzhongLunci(ppxiangmuId,mmPinzhongOne,pplunci);
                    if (mmPinguilist.size()>0){
                        mmPinzhongHebingshu = mmPinguilist.size();
                    }else{
                        mmPinzhongHebingshu = mmPinzhongHebingshu+1;
                    }
                    List<Map<String,Object>> mmPinguiFenlei = ddService.findPinguiFenleiLunci(ppxiangmuId,mmPinzhongOne,pplunci);
                    for (int j = 0; j < mmPinguiFenlei.size(); j++) {
                        int mmPinguiHebingshu = 0;
                        Map<String,Object> mmPinguiMap = mmPinguiFenlei.get(j);
                        if (mmPinguiMap!=null){
                            String mmPinguiOne = mmPinguiMap.get("pinguixuhao") == null ? "" : mmPinguiMap.get("pinguixuhao").toString();
                            List<Map<String,Object>> mmShengchanqiyelist = ddService.findShengchanqiyeByPinguiResult(ppxiangmuId,mmPinguiOne,ppuserId,pplunci);

//                            if (pplunci>1){
//                                for (int k=0;k<mmShengchanqiyelist.size();k++){
//                                    String mmDetailId = mmShengchanqiyelist.get(k).get("id").toString();
//                                    int Score = ddShengchanqiyelinxuanzhongjianjieguoService.findByDetailIdAndLunci(mmDetailId,pplunci-1).getScore();
//                                    mmShengchanqiyelist.get(k).put("lastscore",Score);
//                                }
//                            }
                            if (mmShengchanqiyelist.size()>0){
                                mmPinguiHebingshu = mmShengchanqiyelist.size();
                            }else{
                                mmPinguiHebingshu = mmPinguiHebingshu+1;
                            }
                            mmPinguiMap.put("shengchanqiyelist",mmShengchanqiyelist);
                            mmPinguiMap.put("pinguihebinghang",mmPinguiHebingshu);
                            mmPinguiList.add(mmPinguiMap);
                        }
                    }
                    mmMap.put("pinguilist",mmPinguiList);
                    mmMap.put("pinzhonghebinghang",mmPinzhongHebingshu);
                }
                mmShengchanList.add(mmMap);
            }
            Integer mmCount = ddService.getPinguiCount(ppxiangmuId,String.valueOf(pplunci),ppPageIndex,ppPageSize);
            PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);

            Map<String, Object> mmReturnMap = new HashMap<String, Object>();
            mmReturnMap.put("ShengchanList", mmShengchanList);
            mmReturnMap.put("PageInfo", mmPageInfo);
            return JsonResult.getSuccessResult(mmReturnMap);

        }catch (Exception e) {
            e.printStackTrace();
            log.error("shengchanqiye/findBiaojuelist:error",e);
            return JsonResult.getErrorResult("shengchanqiye/findBiaojuelist:error " + e.getMessage());
        }

    }


    @RequestMapping("findshengchanqiyelist")
    public JsonResult<?> findShengchanqiyelist(@RequestParam("xiangmuid") String ppxiangmuId, @RequestParam("pageindex") int ppPageIndex,
                                               @RequestParam("pagesize") int ppPageSize){
        try {
            Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppxiangmuId);
            Integer mmlunci=mmYsxiangmu.getLunci();
            List<Map<String,Object>> mmShengchanList = new ArrayList<>();
            List<Map<String,Object>> mmPinzhongAll = ddService.findPinzhongBySuijilunci(ppxiangmuId,String.valueOf(mmlunci),ppPageIndex,ppPageSize);
            for (int i = 0; i < mmPinzhongAll.size(); i++) {
                int mmPinzhongHebingshu = 0;
                Map<String,Object> mmMap = mmPinzhongAll.get(i);
                if (mmMap!=null){
                    List<Map<String,Object>> mmPinguiList = new ArrayList<>();
                    String mmPinzhongOne = mmMap.get("pinzhongbianhao") == null ? "" : mmMap.get("pinzhongbianhao").toString();
                    List<Map<String,Object>> mmPinguilist = ddService.findPinguiByPinzhong(ppxiangmuId,mmPinzhongOne);
                    if (mmPinguilist.size()>0){
                        mmPinzhongHebingshu = mmPinguilist.size();
                    }else{
                        mmPinzhongHebingshu = mmPinzhongHebingshu+1;
                    }
                    List<Map<String,Object>> mmPinguiFenlei = ddService.findPinguiFenlei(ppxiangmuId,mmPinzhongOne);
                    for (int j = 0; j < mmPinguiFenlei.size(); j++) {
                        int mmPinguiHebingshu = 0;
                        Map<String,Object> mmPinguiMap = mmPinguiFenlei.get(j);
                        if (mmPinguiMap!=null){
                            String mmPinguiOne = mmPinguiMap.get("pinguixuhao") == null ? "" : mmPinguiMap.get("pinguixuhao").toString();
                            List<Map<String,Object>> mmShengchanqiyelist = ddService.findShengchanqiyeByPingui(ppxiangmuId,mmPinguiOne);
                            if (mmShengchanqiyelist.size()>0){
                                mmPinguiHebingshu = mmShengchanqiyelist.size();
                            }else{
                                mmPinguiHebingshu = mmPinguiHebingshu+1;
                            }
                            mmPinguiMap.put("shengchanqiyelist",mmShengchanqiyelist);
                            mmPinguiMap.put("pinguihebinghang",mmPinguiHebingshu);
                            mmPinguiList.add(mmPinguiMap);
                        }
                    }
                    mmMap.put("pinguilist",mmPinguiList);
                    mmMap.put("pinzhonghebinghang",mmPinzhongHebingshu);
                }
                mmShengchanList.add(mmMap);
            }
            Integer mmCount = ddService.getPinguiCount(ppxiangmuId,mmsuijilunci,ppPageIndex,ppPageSize);
            PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);

            Map<String, Object> mmReturnMap = new HashMap<String, Object>();
            mmReturnMap.put("ShengchanList", mmShengchanList);
            mmReturnMap.put("PageInfo", mmPageInfo);
            return JsonResult.getSuccessResult(mmReturnMap);

        }catch (Exception e) {
            e.printStackTrace();
            log.error("shengchanqiye/findshengchanqiyelist:error",e);
            return JsonResult.getErrorResult("shengchanqiye/findshengchanqiyelist:error " + e.getMessage());
        }

    }

    @RequestMapping("huizongbiao")
    public void huizongbiao(HttpServletRequest request, HttpServletResponse response,
                            @RequestParam("xiangmuid") String ppxiangmuid,
                            @RequestParam("xiangmuleixing") String ppxiangmuleixing){
        List<Ysrenyuanfenpei> mmUserList=ddYsrenyuanfenpeiService.findUserByXiangmuId(ppxiangmuid);
        List<Map<String,Object>> mmPinguiList=ddService.findPinguiAll(ppxiangmuid,1,9999);
        List<Map<String,Object>> mmPinzhongAll = ddService.findPinzhongAll(ppxiangmuid,1,9999);


        response.reset();
        response.setContentType("application/x-download;charset=utf-8");
        OutputStream os=null;
        WritableWorkbook wbook=null;

        try {
            os = new BufferedOutputStream(response.getOutputStream());//得到输出流的语句
            //response.getOutputStream();// 取得输出流
            response.reset();// 清空输出流
            SimpleDateFormat mmDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
            String wenjiantitle = "汇总生产企业遴选信息比对表" + StringHandle.tiemString(); //文件名
            String tmptitle = "生产企业遴选信息比对表"; // 标题
            response.setHeader("Content-disposition", "attachment; filename=" + new String(wenjiantitle.getBytes(), "iso8859-1") + ".xls");// 设定输出文件头
            response.setContentType("application/vnd.ms-excel");// 定义输出类型
            wbook = Workbook.createWorkbook(os); // 建立excel文件
            WritableSheet wsheet = wbook.createSheet(tmptitle, 0); // sheet名称
            // 设置excel标题
            WritableFont wfont = new WritableFont(WritableFont.ARIAL, 24, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式

            WritableCellFormat wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); // 添加边框
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            //wcfFC.setBackground(Colour.AQUA);

            WritableCellFormat wcfFC3 = new WritableCellFormat(wfont);
            wcfFC3.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC3.setAlignment(Alignment.CENTRE);
            //wcfFC.setBackground(Colour.AQUA);
            Label label=new Label(0, 0, tmptitle, wcfFC3);

            WritableCellFormat cellFormat = new WritableCellFormat();
            cellFormat.setAlignment(jxl.format.Alignment.CENTRE);
            cellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
            cellFormat.setWrap(true);
            //cellFormat.setBackground(Colour.AQUA);
            cellFormat.setFont(wfont);
            label.setCellFormat(cellFormat);
            wsheet.addCell(label);
            wsheet.addCell(new Label(0, 0, tmptitle, wcfFC3));
            /*wsheet.addCell(new Label(7, 0, tmptitle, wcfFC));*/
            wsheet.setRowView(0,800); //第一行高度
            wsheet.setRowView(1,600); //第二行高度
            wsheet.mergeCells(0, 0, 24, 0);  //合并单元格(第一列的第一行和第十三列的第一行合并)
            wsheet.setColumnView(0,5); //编号宽度
            wsheet.setColumnView(1,5); //药品宽度
            wsheet.setColumnView(2,5); //剂型宽度
            wsheet.setColumnView(3,5); //序号宽度
            wsheet.setColumnView(4,10); //药品名称宽度
            wsheet.setColumnView(5,8); //规格宽度
            wsheet.setColumnView(6,5); //单位
            wsheet.setColumnView(7,5); //医保类别
            wsheet.setColumnView(8,8); //1宽度
            wsheet.setColumnView(9,8); //2宽度
            wsheet.setColumnView(10,8); //3宽度
            wsheet.setColumnView(11,8); //1宽度
            wsheet.setColumnView(12,10); //2宽度
            wsheet.setColumnView(13,10); //3宽度
            wsheet.setColumnView(14,10); //4宽度
            wsheet.setColumnView(15,8); //1宽度
            wsheet.setColumnView(16,8); //2宽度
            wsheet.setColumnView(17,5); //基药宽度
            wsheet.setColumnView(18,5); //集采宽度
            wsheet.setColumnView(19,5); //院本部宽度
            wsheet.setColumnView(20,5); //秦淮宽度
            wsheet.setColumnView(21,10); //产品编码宽度
            wsheet.setColumnView(22,10); //生产企业宽度
            wsheet.setColumnView(23,10); //备注宽度
            wsheet.setColumnView(24,5); //品规类别宽度
            // 开始生成主体内容
            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);

            wsheet.addCell(new Label(0, 1, "编号",wcfFC));
            wsheet.mergeCells(0, 1, 0, 2);
            wsheet.addCell(new Label(1, 1, "药品品名",wcfFC));
            wsheet.mergeCells(1, 1, 1, 2);
            wsheet.addCell(new Label(2, 1, "剂型",wcfFC));
            wsheet.mergeCells(2, 1, 2, 2);
            wsheet.addCell(new Label(3, 1, "序号",wcfFC));
            wsheet.mergeCells(3, 1, 3, 2);
            wsheet.addCell(new Label(4, 1, "药品名称",wcfFC));
            wsheet.mergeCells(4, 1, 4, 2);
            wsheet.addCell(new Label(5, 1, "规格",wcfFC));
            wsheet.mergeCells(5, 1, 5, 2);
            wsheet.addCell(new Label(6, 1, "单位",wcfFC));
            wsheet.mergeCells(6, 1, 6, 2);
            wsheet.addCell(new Label(7, 1, "医保类别",wcfFC));
            wsheet.mergeCells(7, 1, 7, 2);

            wsheet.addCell(new Label(8, 1, "上级检查通报",wcfFC));
            wsheet.addCell(new Label(9, 1, "未挂网",wcfFC));
            wsheet.addCell(new Label(10, 1, "无配送企业",wcfFC));


            wsheet.addCell(new Label(11, 1, "原国谈",wcfFC));
            wsheet.addCell(new Label(12, 1, "通过一致性评价",wcfFC));
            wsheet.addCell(new Label(13, 1, "国家保密配方",wcfFC));
            wsheet.addCell(new Label(14, 1, "中药保护品种",wcfFC));

            wsheet.addCell(new Label(15, 1, "价格（元）",wcfFC));
            wsheet.addCell(new Label(16, 1, "原研",wcfFC));


            wsheet.addCell(new Label(17, 1, "基药",wcfFC));
            wsheet.mergeCells(17, 1, 17, 2);
            wsheet.addCell(new Label(18, 1, "集采",wcfFC));
            wsheet.mergeCells(18, 1, 18, 2);
            wsheet.addCell(new Label(19, 1, "院本部",wcfFC));
            wsheet.mergeCells(19, 1, 19, 2);
            wsheet.addCell(new Label(20, 1, "秦淮",wcfFC));
            wsheet.mergeCells(20, 1, 20, 2);
            wsheet.addCell(new Label(21, 1, "产品编码",wcfFC));
            wsheet.mergeCells(21, 1, 21, 2);
            wsheet.addCell(new Label(22, 1, "生产企业",wcfFC));
            wsheet.mergeCells(22, 1, 22, 2);
            wsheet.addCell(new Label(23, 1, "备注",wcfFC));
            wsheet.mergeCells(23, 1, 23, 2);
            wsheet.addCell(new Label(24, 1, "品规类别",wcfFC));
            wsheet.mergeCells(24, 1, 24, 2);

            // 第四行内容
            wsheet.addCell(new Label(8, 2, "淘汰原则",wcfFC));
            wsheet.mergeCells(8, 2, 10, 2);
            wsheet.addCell(new Label(11, 2, "绝对优先",wcfFC));
            wsheet.mergeCells(11, 2, 14, 2);
            wsheet.addCell(new Label(15, 2, "相对优先",wcfFC));
            wsheet.mergeCells(15, 2, 16, 2);


            // 表头结束

            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);

            int count = mmPinguiList.size();
            int mmKaishihang1 = 3;
            int mmKaishihang2 = 3;
            int mmKaishihang3 = 3;


            int a=1;
            /*for (Map<String, Object> mmPinguiMap : mmPinguiList) {

                a=a+1;
                String mmPinguiOne = mmPinguiMap.get("pinguixuhao").toString();
                String mmYaopinmingcheng = mmPinguiMap.get("yaopinmingcheng").toString();
                String mmGuige = mmPinguiMap.get("guige").toString();
                String mmDanwei = mmPinguiMap.get("danwei").toString();
                String mmYibaoleibie = mmPinguiMap.get("yibaoleibie").toString();

                int mmHebingshu = 0;

                List<Map<String,Object>> mmShengchanqiyelist = ddService.findShengchanqiyeByPingui(ppxiangmuid,mmPinguiOne);
                if (mmShengchanqiyelist.size()>0){
                    mmHebingshu = mmShengchanqiyelist.size()-1;
                }
                int pg=0;
                for (Map<String, Object> mmMap : mmShengchanqiyelist) {
                    pg=pg+1;


                    String mmjianchatongbao = mmMap.get("jianchatongbao")==null ? "" :mmMap.get("jianchatongbao").toString();
                    String mmweiguawang=mmMap.get("weiguawang")==null ? "" :mmMap.get("weiguawang").toString();
                    String mmwupeisongqiye=mmMap.get("wupeisongqiye")==null ? "" :mmMap.get("wupeisongqiye").toString();
                    String mmyuanguotan=mmMap.get("yuanguotan")==null ? "" :mmMap.get("yuanguotan").toString();
                    String mmyizhixingpingjia=mmMap.get("yizhixingpingjia")==null ? "" :mmMap.get("yizhixingpingjia").toString();
                    String mmbaomipeifang=mmMap.get("baomipeifang")==null ? "" :mmMap.get("baomipeifang").toString();
                    String mmbaohupinzhong=mmMap.get("baohupinzhong")==null ? "" :mmMap.get("baohupinzhong").toString();
                    String mmjiage=mmMap.get("jiage")==null ? "" :mmMap.get("jiage").toString();
                    String mmyuanyan=mmMap.get("yuanyan")==null ? "" :mmMap.get("yuanyan").toString();
                    String mmjiyao=mmMap.get("jiyao")==null ? "" :mmMap.get("jiyao").toString();
                    String mmjicai=mmMap.get("jicai")==null ? "" :mmMap.get("jicai").toString();
                    String mmyuanbenbu=mmMap.get("yuanbenbu")==null ? "" :mmMap.get("yuanbenbu").toString();
                    String mmqinhuai=mmMap.get("qinhuai")==null ? "" :mmMap.get("qinhuai").toString();
                    String mmchanpinbianma=mmMap.get("chanpinbianma")==null ? "" :mmMap.get("chanpinbianma").toString();
                    String mmshengchanqiye=mmMap.get("shengchanqiye")==null ? "" :mmMap.get("shengchanqiye").toString();
                    String mmbeizhu=mmMap.get("beizhu")==null ? "" :mmMap.get("beizhu").toString();

                    WritableCellFormat alignStyle = new WritableCellFormat(); //单元格样式
                    alignStyle.setBackground(Colour.GREEN); //背静色

                    wsheet.addCell(new Label(5, mmKaishihang2,mmjianchatongbao,wcfFC));
                    wsheet.addCell(new Label(6, mmKaishihang2,mmweiguawang,wcfFC));
                    wsheet.addCell(new Label(7, mmKaishihang2,mmwupeisongqiye,wcfFC));
                    wsheet.addCell(new Label(8, mmKaishihang2,mmyuanguotan,wcfFC));
                    wsheet.addCell(new Label(9, mmKaishihang2,mmyizhixingpingjia,wcfFC));
                    wsheet.addCell(new Label(10, mmKaishihang2,mmbaomipeifang,wcfFC));
                    wsheet.addCell(new Label(11, mmKaishihang2,mmbaohupinzhong,wcfFC));
                    wsheet.addCell(new Label(12, mmKaishihang2,mmjiage,wcfFC));
                    wsheet.addCell(new Label(13, mmKaishihang2,mmyuanyan,wcfFC));
                    wsheet.addCell(new Label(14, mmKaishihang2,mmjiyao,wcfFC));
                    wsheet.addCell(new Label(15, mmKaishihang2,mmjicai,wcfFC));
                    wsheet.addCell(new Label(16, mmKaishihang2,mmyuanbenbu,wcfFC));
                    wsheet.addCell(new Label(17, mmKaishihang2,mmqinhuai,wcfFC));
                    wsheet.addCell(new Label(18, mmKaishihang2,mmchanpinbianma,wcfFC));
                    wsheet.addCell(new Label(19, mmKaishihang2,mmshengchanqiye,wcfFC));
                    wsheet.addCell(new Label(20, mmKaishihang2,mmbeizhu,wcfFC));

                    mmKaishihang2 = mmKaishihang2+1;

                }
               *//* wsheet.addCell(new Label(0, mmKaishihang1, String.valueOf(a-1),wcfFC));
                wsheet.mergeCells(0, mmKaishihang1, 0, mmKaishihang1+mmHebingshu);*//*
                wsheet.addCell(new Label(0, mmKaishihang1, mmPinguiOne,wcfFC));
                wsheet.addCell(new Label(1, mmKaishihang1, mmYaopinmingcheng,wcfFC));
                wsheet.addCell(new Label(2, mmKaishihang1, mmGuige,wcfFC));
                wsheet.addCell(new Label(3, mmKaishihang1, mmDanwei,wcfFC));
                wsheet.addCell(new Label(4, mmKaishihang1, mmYibaoleibie,wcfFC));

                wsheet.mergeCells(0, mmKaishihang1, 0, mmKaishihang1+mmHebingshu);
                wsheet.mergeCells(1, mmKaishihang1, 1, mmKaishihang1+mmHebingshu);
                wsheet.mergeCells(2, mmKaishihang1, 2, mmKaishihang1+mmHebingshu);
                wsheet.mergeCells(3, mmKaishihang1, 3, mmKaishihang1+mmHebingshu);
                wsheet.mergeCells(4, mmKaishihang1, 4, mmKaishihang1+mmHebingshu);
                *//*  wsheet.mergeCells(5, mmKaishihang1, 5, mmKaishihang1+mmHebingshu);*//*
                *//*wsheet.mergeCells(6, mmKaishihang1, 6, mmKaishihang1+mmHebingshu);*//*
                mmKaishihang1 = mmKaishihang1+mmHebingshu+1;

            }*/
            for (Map<String, Object> mmPinzhongMap : mmPinzhongAll) {

                int mmPinzhongHebingshu = 0;
                String mmPinzhongOne = mmPinzhongMap.get("pinzhongbianhao").toString();
                String mmYaopinpinming = mmPinzhongMap.get("yaopinpinming").toString();
                String mmJixing = mmPinzhongMap.get("jixing").toString();

                List<Map<String,Object>> mmPinguilist = ddService.findPinguiByPinzhong(ppxiangmuid,mmPinzhongOne);
                if (mmPinguilist.size()>0){
                    mmPinzhongHebingshu = mmPinguilist.size()-1;
                }
                List<Map<String,Object>> mmPinguiFenlei = ddService.findPinguiFenlei(ppxiangmuid,mmPinzhongOne);

                for (Map<String, Object> mmPinguiMap : mmPinguiFenlei) {

                    a=a+1;
                    String mmPinguiOne = mmPinguiMap.get("pinguixuhao").toString();
                    String mmYaopinmingcheng = mmPinguiMap.get("yaopinmingcheng").toString();
                    String mmGuige = mmPinguiMap.get("guige").toString();
                    String mmDanwei = mmPinguiMap.get("danwei").toString();
                    String mmYibaoleibie = mmPinguiMap.get("yibaoleibie").toString();
                    String mmPinguileibie = mmPinguiMap.get("pinguileibie").toString();

                    int mmHebingshu = 0;

                    List<Map<String,Object>> mmShengchanqiyelist = ddService.findShengchanqiyeByPingui(ppxiangmuid,mmPinguiOne);
                    if (mmShengchanqiyelist.size()>0){
                        mmHebingshu = mmShengchanqiyelist.size()-1;
                    }
                    int pg=0;
                    for (Map<String, Object> mmMap : mmShengchanqiyelist) {
                        pg=pg+1;

                        String mmjianchatongbao = mmMap.get("jianchatongbao")==null ? "" :mmMap.get("jianchatongbao").toString();
                        String mmweiguawang=mmMap.get("weiguawang")==null ? "" :mmMap.get("weiguawang").toString();
                        String mmwupeisongqiye=mmMap.get("wupeisongqiye")==null ? "" :mmMap.get("wupeisongqiye").toString();
                        String mmyuanguotan=mmMap.get("yuanguotan")==null ? "" :mmMap.get("yuanguotan").toString();
                        String mmyizhixingpingjia=mmMap.get("yizhixingpingjia")==null ? "" :mmMap.get("yizhixingpingjia").toString();
                        String mmbaomipeifang=mmMap.get("baomipeifang")==null ? "" :mmMap.get("baomipeifang").toString();
                        String mmbaohupinzhong=mmMap.get("baohupinzhong")==null ? "" :mmMap.get("baohupinzhong").toString();
                        String mmjiage=mmMap.get("jiage")==null ? "" :mmMap.get("jiage").toString();
                        String mmyuanyan=mmMap.get("yuanyan")==null ? "" :mmMap.get("yuanyan").toString();
                        String mmjiyao=mmMap.get("jiyao")==null ? "" :mmMap.get("jiyao").toString();
                        String mmjicai=mmMap.get("jicai")==null ? "" :mmMap.get("jicai").toString();
                        String mmyuanbenbu=mmMap.get("yuanbenbu")==null ? "" :mmMap.get("yuanbenbu").toString();
                        String mmqinhuai=mmMap.get("qinhuai")==null ? "" :mmMap.get("qinhuai").toString();
                        String mmchanpinbianma=mmMap.get("chanpinbianma")==null ? "" :mmMap.get("chanpinbianma").toString();
                        String mmshengchanqiye=mmMap.get("shengchanqiye")==null ? "" :mmMap.get("shengchanqiye").toString();
                        String mmbeizhu=mmMap.get("beizhu")==null ? "" :mmMap.get("beizhu").toString();

                        WritableCellFormat alignStyle = new WritableCellFormat(); //单元格样式
                        alignStyle.setBackground(Colour.GREEN); //背静色

                        wsheet.addCell(new Label(8, mmKaishihang3,mmjianchatongbao,wcfFC));
                        wsheet.addCell(new Label(9, mmKaishihang3,mmweiguawang,wcfFC));
                        wsheet.addCell(new Label(10, mmKaishihang3,mmwupeisongqiye,wcfFC));
                        wsheet.addCell(new Label(11, mmKaishihang3,mmyuanguotan,wcfFC));
                        wsheet.addCell(new Label(12, mmKaishihang3,mmyizhixingpingjia,wcfFC));
                        wsheet.addCell(new Label(13, mmKaishihang3,mmbaomipeifang,wcfFC));
                        wsheet.addCell(new Label(14, mmKaishihang3,mmbaohupinzhong,wcfFC));
                        wsheet.addCell(new Label(15, mmKaishihang3,mmjiage,wcfFC));
                        wsheet.addCell(new Label(16, mmKaishihang3,mmyuanyan,wcfFC));
                        wsheet.addCell(new Label(17, mmKaishihang3,mmjiyao,wcfFC));
                        wsheet.addCell(new Label(18, mmKaishihang3,mmjicai,wcfFC));
                        wsheet.addCell(new Label(19, mmKaishihang3,mmyuanbenbu,wcfFC));
                        wsheet.addCell(new Label(20, mmKaishihang3,mmqinhuai,wcfFC));
                        wsheet.addCell(new Label(21, mmKaishihang3,mmchanpinbianma,wcfFC));
                        wsheet.addCell(new Label(22, mmKaishihang3,mmshengchanqiye,wcfFC));
                        wsheet.addCell(new Label(23, mmKaishihang3,mmbeizhu,wcfFC));
                        mmKaishihang3 = mmKaishihang3+1;
                    }
                    wsheet.addCell(new Label(3, mmKaishihang2, mmPinguiOne,wcfFC));
                    wsheet.addCell(new Label(4, mmKaishihang2, mmYaopinmingcheng,wcfFC));
                    wsheet.addCell(new Label(5, mmKaishihang2, mmGuige,wcfFC));
                    wsheet.addCell(new Label(6, mmKaishihang2, mmDanwei,wcfFC));
                    wsheet.addCell(new Label(7, mmKaishihang2, mmYibaoleibie,wcfFC));
                    wsheet.addCell(new Label(24, mmKaishihang2, mmPinguileibie,wcfFC));
                    wsheet.mergeCells(3, mmKaishihang2, 3, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(4, mmKaishihang2, 4, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(5, mmKaishihang2, 5, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(6, mmKaishihang2, 6, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(7, mmKaishihang2, 7, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(24, mmKaishihang2, 24, mmKaishihang2+mmHebingshu);
                    mmKaishihang2 = mmKaishihang2+mmHebingshu+1;
                }
                wsheet.addCell(new Label(0, mmKaishihang1, mmPinzhongOne,wcfFC));
                wsheet.mergeCells(0, mmKaishihang1, 0, mmKaishihang1+mmPinzhongHebingshu);
                wsheet.addCell(new Label(1, mmKaishihang1, mmYaopinpinming,wcfFC));
                wsheet.mergeCells(1, mmKaishihang1, 1, mmKaishihang1+mmPinzhongHebingshu);
                wsheet.addCell(new Label(2, mmKaishihang1, mmJixing,wcfFC));
                wsheet.mergeCells(2, mmKaishihang1, 2, mmKaishihang1+mmPinzhongHebingshu);
                mmKaishihang1 = mmKaishihang1+mmPinzhongHebingshu+1;

            }
            wbook.write(); // 写入文件
            wbook.close();
        } catch(Exception ex)
        {
            ex.printStackTrace();
        }finally{
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
    /*@RequestMapping("dangqianbiao")
    public void dangqianbiao(HttpServletRequest request, HttpServletResponse response,
                            @RequestParam("xiangmuid") String ppxiangmuid){
        List<Map<String,Object>> mmPinguiList=ddService.findPinguiBySuijilunci(ppxiangmuid,mmsuijilunci,1,9999);
        List<Map<String,Object>> mmPinzhongAll = ddService.findPinzhongBySuijilunci(ppxiangmuid,mmsuijilunci,1,9999);

        response.reset();
        response.setContentType("application/x-download;charset=utf-8");
        OutputStream os=null;
        WritableWorkbook wbook=null;

        try {
            os = new BufferedOutputStream(response.getOutputStream());//得到输出流的语句
            //response.getOutputStream();// 取得输出流
            response.reset();// 清空输出流
            SimpleDateFormat mmDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
            String wenjiantitle = "随机抽取生产企业遴选信息比对表" + StringHandle.tiemString(); //文件名
            String tmptitle = "生产企业遴选信息比对表"; // 标题
            response.setHeader("Content-disposition", "attachment; filename=" + new String(wenjiantitle.getBytes(), "iso8859-1") + ".xls");// 设定输出文件头
            response.setContentType("application/vnd.ms-excel");// 定义输出类型
            wbook = Workbook.createWorkbook(os); // 建立excel文件
            WritableSheet wsheet = wbook.createSheet(tmptitle, 0); // sheet名称
            // 设置excel标题
            WritableFont wfont = new WritableFont(WritableFont.ARIAL, 24, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式

            WritableCellFormat wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); // 添加边框
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);

            WritableCellFormat wcfFC3 = new WritableCellFormat(wfont);
            wcfFC3.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC3.setAlignment(Alignment.CENTRE);
            //wcfFC.setBackground(Colour.AQUA);
            Label label=new Label(0, 0, tmptitle, wcfFC3);

            WritableCellFormat cellFormat = new WritableCellFormat();
            cellFormat.setAlignment(jxl.format.Alignment.CENTRE);
            cellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
            cellFormat.setWrap(true);
            //cellFormat.setBackground(Colour.AQUA);
            cellFormat.setFont(wfont);
            label.setCellFormat(cellFormat);
            wsheet.addCell(label);
            wsheet.addCell(new Label(0, 0, tmptitle, wcfFC3));
            *//*wsheet.addCell(new Label(7, 0, tmptitle, wcfFC));*//*
            wsheet.setRowView(0,800); //第一行高度
            wsheet.setRowView(1,600); //第二行高度
            wsheet.mergeCells(0, 0, 24, 0);  //合并单元格(第一列的第一行和第十三列的第一行合并)
            wsheet.setColumnView(0,5); //编号宽度
            wsheet.setColumnView(1,5); //药品宽度
            wsheet.setColumnView(2,5); //剂型宽度
            wsheet.setColumnView(3,5); //序号宽度
            wsheet.setColumnView(4,10); //药品名称宽度
            wsheet.setColumnView(5,8); //规格宽度
            wsheet.setColumnView(6,5); //单位
            wsheet.setColumnView(7,5); //医保类别
            wsheet.setColumnView(8,8); //1宽度
            wsheet.setColumnView(9,8); //2宽度
            wsheet.setColumnView(10,8); //3宽度
            wsheet.setColumnView(11,8); //1宽度
            wsheet.setColumnView(12,10); //2宽度
            wsheet.setColumnView(13,10); //3宽度
            wsheet.setColumnView(14,10); //4宽度
            wsheet.setColumnView(15,8); //1宽度
            wsheet.setColumnView(16,8); //2宽度
            wsheet.setColumnView(17,5); //基药宽度
            wsheet.setColumnView(18,5); //集采宽度
            wsheet.setColumnView(19,5); //院本部宽度
            wsheet.setColumnView(20,5); //秦淮宽度
            wsheet.setColumnView(21,10); //产品编码宽度
            wsheet.setColumnView(22,10); //生产企业宽度
            wsheet.setColumnView(23,10); //备注宽度
            wsheet.setColumnView(24,5); //品规类别宽度
            // 开始生成主体内容
            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);

            wsheet.addCell(new Label(0, 1, "编号",wcfFC));
            wsheet.mergeCells(0, 1, 0, 2);
            wsheet.addCell(new Label(1, 1, "药品品名",wcfFC));
            wsheet.mergeCells(1, 1, 1, 2);
            wsheet.addCell(new Label(2, 1, "剂型",wcfFC));
            wsheet.mergeCells(2, 1, 2, 2);
            wsheet.addCell(new Label(3, 1, "序号",wcfFC));
            wsheet.mergeCells(3, 1, 3, 2);
            wsheet.addCell(new Label(4, 1, "药品名称",wcfFC));
            wsheet.mergeCells(4, 1, 4, 2);
            wsheet.addCell(new Label(5, 1, "规格",wcfFC));
            wsheet.mergeCells(5, 1, 5, 2);
            wsheet.addCell(new Label(6, 1, "单位",wcfFC));
            wsheet.mergeCells(6, 1, 6, 2);
            wsheet.addCell(new Label(7, 1, "医保类别",wcfFC));
            wsheet.mergeCells(7, 1, 7, 2);

            wsheet.addCell(new Label(8, 1, "上级检查通报",wcfFC));
            wsheet.addCell(new Label(9, 1, "未挂网",wcfFC));
            wsheet.addCell(new Label(10, 1, "无配送企业",wcfFC));


            wsheet.addCell(new Label(11, 1, "原国谈",wcfFC));
            wsheet.addCell(new Label(12, 1, "通过一致性评价",wcfFC));
            wsheet.addCell(new Label(13, 1, "国家保密配方",wcfFC));
            wsheet.addCell(new Label(14, 1, "中药保护品种",wcfFC));

            wsheet.addCell(new Label(15, 1, "价格（元）",wcfFC));
            wsheet.addCell(new Label(16, 1, "原研",wcfFC));


            wsheet.addCell(new Label(17, 1, "基药",wcfFC));
            wsheet.mergeCells(17, 1, 17, 2);
            wsheet.addCell(new Label(18, 1, "集采",wcfFC));
            wsheet.mergeCells(18, 1, 18, 2);
            wsheet.addCell(new Label(19, 1, "院本部",wcfFC));
            wsheet.mergeCells(19, 1, 19, 2);
            wsheet.addCell(new Label(20, 1, "秦淮",wcfFC));
            wsheet.mergeCells(20, 1, 20, 2);
            wsheet.addCell(new Label(21, 1, "产品编码",wcfFC));
            wsheet.mergeCells(21, 1, 21, 2);
            wsheet.addCell(new Label(22, 1, "生产企业",wcfFC));
            wsheet.mergeCells(22, 1, 22, 2);
            wsheet.addCell(new Label(23, 1, "备注",wcfFC));
            wsheet.mergeCells(23, 1, 23, 2);
            wsheet.addCell(new Label(24, 1, "品规类别",wcfFC));
            wsheet.mergeCells(24, 1, 24, 2);

            // 第四行内容
            wsheet.addCell(new Label(8, 2, "淘汰原则",wcfFC));
            wsheet.mergeCells(8, 2, 10, 2);
            wsheet.addCell(new Label(11, 2, "绝对优先",wcfFC));
            wsheet.mergeCells(11, 2, 14, 2);
            wsheet.addCell(new Label(15, 2, "相对优先",wcfFC));
            wsheet.mergeCells(15, 2, 16, 2);


            // 表头结束

            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);

            int count = mmPinguiList.size();
            int mmKaishihang1 = 3;
            int mmKaishihang2 = 3;
            int mmKaishihang3 = 3;


            int a=1;
            for (Map<String, Object> mmPinzhongMap : mmPinzhongAll) {

                int mmPinzhongHebingshu = 0;
                String mmPinzhongOne = mmPinzhongMap.get("pinzhongbianhao").toString();
                String mmYaopinpinming = mmPinzhongMap.get("yaopinpinming").toString();
                String mmJixing = mmPinzhongMap.get("jixing").toString();

                List<Map<String,Object>> mmPinguilist = ddService.findPinguiByPinzhong(ppxiangmuid,mmPinzhongOne);
                if (mmPinguilist.size()>0){
                    mmPinzhongHebingshu = mmPinguilist.size()-1;
                }
                List<Map<String,Object>> mmPinguiFenlei = ddService.findPinguiFenlei(ppxiangmuid,mmPinzhongOne);

                for (Map<String, Object> mmPinguiMap : mmPinguiFenlei) {

                    a=a+1;
                    String mmPinguiOne = mmPinguiMap.get("pinguixuhao").toString();
                    String mmYaopinmingcheng = mmPinguiMap.get("yaopinmingcheng").toString();
                    String mmGuige = mmPinguiMap.get("guige").toString();
                    String mmDanwei = mmPinguiMap.get("danwei").toString();
                    String mmYibaoleibie = mmPinguiMap.get("yibaoleibie").toString();
                    String mmPinguileibie = mmPinguiMap.get("pinguileibie").toString();

                    int mmHebingshu = 0;

                    List<Map<String,Object>> mmShengchanqiyelist = ddService.findShengchanqiyeByPingui(ppxiangmuid,mmPinguiOne);
                    if (mmShengchanqiyelist.size()>0){
                        mmHebingshu = mmShengchanqiyelist.size()-1;
                    }
                    int pg=0;
                    for (Map<String, Object> mmMap : mmShengchanqiyelist) {
                        pg=pg+1;

                        String mmjianchatongbao = mmMap.get("jianchatongbao")==null ? "" :mmMap.get("jianchatongbao").toString();
                        String mmweiguawang=mmMap.get("weiguawang")==null ? "" :mmMap.get("weiguawang").toString();
                        String mmwupeisongqiye=mmMap.get("wupeisongqiye")==null ? "" :mmMap.get("wupeisongqiye").toString();
                        String mmyuanguotan=mmMap.get("yuanguotan")==null ? "" :mmMap.get("yuanguotan").toString();
                        String mmyizhixingpingjia=mmMap.get("yizhixingpingjia")==null ? "" :mmMap.get("yizhixingpingjia").toString();
                        String mmbaomipeifang=mmMap.get("baomipeifang")==null ? "" :mmMap.get("baomipeifang").toString();
                        String mmbaohupinzhong=mmMap.get("baohupinzhong")==null ? "" :mmMap.get("baohupinzhong").toString();
                        String mmjiage=mmMap.get("jiage")==null ? "" :mmMap.get("jiage").toString();
                        String mmyuanyan=mmMap.get("yuanyan")==null ? "" :mmMap.get("yuanyan").toString();
                        String mmjiyao=mmMap.get("jiyao")==null ? "" :mmMap.get("jiyao").toString();
                        String mmjicai=mmMap.get("jicai")==null ? "" :mmMap.get("jicai").toString();
                        String mmyuanbenbu=mmMap.get("yuanbenbu")==null ? "" :mmMap.get("yuanbenbu").toString();
                        String mmqinhuai=mmMap.get("qinhuai")==null ? "" :mmMap.get("qinhuai").toString();
                        String mmchanpinbianma=mmMap.get("chanpinbianma")==null ? "" :mmMap.get("chanpinbianma").toString();
                        String mmshengchanqiye=mmMap.get("shengchanqiye")==null ? "" :mmMap.get("shengchanqiye").toString();
                        String mmbeizhu=mmMap.get("beizhu")==null ? "" :mmMap.get("beizhu").toString();

                        WritableCellFormat alignStyle = new WritableCellFormat(); //单元格样式
                        alignStyle.setBackground(Colour.GREEN); //背静色

                        wsheet.addCell(new Label(8, mmKaishihang3,mmjianchatongbao,wcfFC));
                        wsheet.addCell(new Label(9, mmKaishihang3,mmweiguawang,wcfFC));
                        wsheet.addCell(new Label(10, mmKaishihang3,mmwupeisongqiye,wcfFC));
                        wsheet.addCell(new Label(11, mmKaishihang3,mmyuanguotan,wcfFC));
                        wsheet.addCell(new Label(12, mmKaishihang3,mmyizhixingpingjia,wcfFC));
                        wsheet.addCell(new Label(13, mmKaishihang3,mmbaomipeifang,wcfFC));
                        wsheet.addCell(new Label(14, mmKaishihang3,mmbaohupinzhong,wcfFC));
                        wsheet.addCell(new Label(15, mmKaishihang3,mmjiage,wcfFC));
                        wsheet.addCell(new Label(16, mmKaishihang3,mmyuanyan,wcfFC));
                        wsheet.addCell(new Label(17, mmKaishihang3,mmjiyao,wcfFC));
                        wsheet.addCell(new Label(18, mmKaishihang3,mmjicai,wcfFC));
                        wsheet.addCell(new Label(19, mmKaishihang3,mmyuanbenbu,wcfFC));
                        wsheet.addCell(new Label(20, mmKaishihang3,mmqinhuai,wcfFC));
                        wsheet.addCell(new Label(21, mmKaishihang3,mmchanpinbianma,wcfFC));
                        wsheet.addCell(new Label(22, mmKaishihang3,mmshengchanqiye,wcfFC));
                        wsheet.addCell(new Label(23, mmKaishihang3,mmbeizhu,wcfFC));
                        mmKaishihang3 = mmKaishihang3+1;
                    }
                    wsheet.addCell(new Label(3, mmKaishihang2, mmPinguiOne,wcfFC));
                    wsheet.addCell(new Label(4, mmKaishihang2, mmYaopinmingcheng,wcfFC));
                    wsheet.addCell(new Label(5, mmKaishihang2, mmGuige,wcfFC));
                    wsheet.addCell(new Label(6, mmKaishihang2, mmDanwei,wcfFC));
                    wsheet.addCell(new Label(7, mmKaishihang2, mmYibaoleibie,wcfFC));
                    wsheet.addCell(new Label(24, mmKaishihang2, mmPinguileibie,wcfFC));
                    wsheet.mergeCells(3, mmKaishihang2, 3, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(4, mmKaishihang2, 4, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(5, mmKaishihang2, 5, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(6, mmKaishihang2, 6, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(7, mmKaishihang2, 7, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(24, mmKaishihang2, 24, mmKaishihang2+mmHebingshu);
                    mmKaishihang2 = mmKaishihang2+mmHebingshu+1;
                }
                wsheet.addCell(new Label(0, mmKaishihang1, mmPinzhongOne,wcfFC));
                wsheet.mergeCells(0, mmKaishihang1, 0, mmKaishihang1+mmPinzhongHebingshu);
                wsheet.addCell(new Label(1, mmKaishihang1, mmYaopinpinming,wcfFC));
                wsheet.mergeCells(1, mmKaishihang1, 1, mmKaishihang1+mmPinzhongHebingshu);
                wsheet.addCell(new Label(2, mmKaishihang1, mmJixing,wcfFC));
                wsheet.mergeCells(2, mmKaishihang1, 2, mmKaishihang1+mmPinzhongHebingshu);
                mmKaishihang1 = mmKaishihang1+mmPinzhongHebingshu+1;

            }


            wbook.write(); // 写入文件
            wbook.close();
        } catch(Exception ex)
        {
            ex.printStackTrace();
        }finally{
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }*/

    @RequestMapping("find_one")
    public JsonResult<?> find_one(@RequestParam("id") String ppId) {
        try {
            return JsonResult.getSuccessResult(ddService.findOne(ppId));

        }catch (Exception e) {
            e.printStackTrace();
            log.error("shengchanqiye/find_one:error",e);
            return JsonResult.getErrorResult("shengchanqiye/find_one:error " + e.getMessage());
        }
    }



    @RequestMapping("modify")
    public JsonResult<?> modify(@RequestParam("id") String ppid,
                                @RequestParam("jianchatongbao") String ppjianchatongbao,
                                @RequestParam("weiguawang") String ppweiguawang,
                                @RequestParam("wupeisongqiye") String ppwupeisongqiye,
                                @RequestParam("yuanguotan") String ppyuanguotan,
                                @RequestParam("yizhixingpingjia") String ppyizhixingpingjia,
                                @RequestParam("baomipeifang") String ppbaomipeifang,
                                @RequestParam("baohupinzhong") String ppbaohupinzhong,
                                @RequestParam("jiage") String ppjiage,
                                @RequestParam("yuanyan") String ppyuanyan,
                                @RequestParam("jiyao") String ppjiyao,
                                @RequestParam("jicai") String ppjicai,
                                @RequestParam("chanpinbianma") String ppchanpinbianma,
                                @RequestParam("shengchanqiye") String ppshengchanqiye,
                                HttpServletRequest request){
        try {

            Shengchanqiyelinxuan mmshengchanqiyelinxuan=new Shengchanqiyelinxuan();
            mmshengchanqiyelinxuan.setId(ppid);
            mmshengchanqiyelinxuan.setUpdatetime(new Date());

            mmshengchanqiyelinxuan.setJianchatongbao(ppjianchatongbao);
            mmshengchanqiyelinxuan.setWeiguawang(ppweiguawang);
            mmshengchanqiyelinxuan.setWupeisongqiye(ppwupeisongqiye);
            mmshengchanqiyelinxuan.setYuanguotan(ppyuanguotan);
            mmshengchanqiyelinxuan.setYizhixingpingjia(ppyizhixingpingjia);
            mmshengchanqiyelinxuan.setBaomipeifang(ppbaomipeifang);
            mmshengchanqiyelinxuan.setBaohupinzhong(ppbaohupinzhong);
            mmshengchanqiyelinxuan.setJiage(ppjiage);
            mmshengchanqiyelinxuan.setYuanyan(ppyuanyan);
            mmshengchanqiyelinxuan.setJiyao(ppjiyao);
            mmshengchanqiyelinxuan.setJicai(ppjicai);
            mmshengchanqiyelinxuan.setChanpinbianma(ppchanpinbianma);
            mmshengchanqiyelinxuan.setShengchanqiye(ppshengchanqiye);

            return ddService.modify(mmshengchanqiyelinxuan)==true? JsonResult.getSuccessResult("保存成功")
                    : JsonResult.getErrorResult("保存失败");


        }catch (Exception e) {
            e.printStackTrace();
            log.error("shengchanqiye/find_one:error",e);
            return JsonResult.getErrorResult("shengchanqiye/find_one:error " + e.getMessage());
        }

    }


    public void smpling(){
        int total=250;
//        String mmsuijilunci="1";
        int leixing1=37;
        int leixing2=133;
        int leixing3=32;
        int leixing4=37;
        int leixing5=11;
        //int leixing6=9;



        int leixing1_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"1").size();
        if(leixing1>leixing1_smplinged){
            List<Map<String,Object>> mmRandomPinzhong=ddService.chouQupinzhong("1");
            if(mmRandomPinzhong.size()>0){
                String mmpinzhongbianhao=mmRandomPinzhong.get(0).get("pinzhongbianhao").toString();
                List<Shengchanqiyelinxuan> mmYaopinlist=ddService.findByPinzhongbianhao(mmpinzhongbianhao);
                for (Shengchanqiyelinxuan mmShengchanqiyelinxuan:mmYaopinlist){
                    String mmid=mmShengchanqiyelinxuan.getId();
                    Shengchanqiyelinxuan mmshengchanqiyelinxuan=new Shengchanqiyelinxuan();
                    mmshengchanqiyelinxuan.setId(mmid);
                    mmshengchanqiyelinxuan.setSuijilunci(mmsuijilunci);
                    ddService.modify(mmshengchanqiyelinxuan);
                }
            }
            leixing1_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"1").size();
            if(leixing1>leixing1_smplinged){
                smpling();
            }
        }

        int leixing2_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"2").size();
        if(leixing2>leixing2_smplinged){
            List<Map<String,Object>> mmRandomPinzhong=ddService.chouQupinzhong("2");
            if(mmRandomPinzhong.size()>0){
                String mmpinzhongbianhao=mmRandomPinzhong.get(0).get("pinzhongbianhao").toString();
                List<Shengchanqiyelinxuan> mmYaopinlist=ddService.findByPinzhongbianhao(mmpinzhongbianhao);
                for (Shengchanqiyelinxuan mmShengchanqiyelinxuan:mmYaopinlist){
                    String mmid=mmShengchanqiyelinxuan.getId();
                    Shengchanqiyelinxuan mmshengchanqiyelinxuan=new Shengchanqiyelinxuan();
                    mmshengchanqiyelinxuan.setId(mmid);
                    mmshengchanqiyelinxuan.setSuijilunci(mmsuijilunci);
                    ddService.modify(mmshengchanqiyelinxuan);
                }
            }
            leixing2_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"2").size();
            if(leixing2>leixing2_smplinged){
                smpling(); 
            }
        }

        int leixing3_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"3").size();
        if(leixing3>leixing3_smplinged){
            List<Map<String,Object>> mmRandomPinzhong=ddService.chouQupinzhong("3");
            if(mmRandomPinzhong.size()>0){
                String mmpinzhongbianhao=mmRandomPinzhong.get(0).get("pinzhongbianhao").toString();
                List<Shengchanqiyelinxuan> mmYaopinlist=ddService.findByPinzhongbianhao(mmpinzhongbianhao);
                for (Shengchanqiyelinxuan mmShengchanqiyelinxuan:mmYaopinlist){
                    String mmid=mmShengchanqiyelinxuan.getId();
                    Shengchanqiyelinxuan mmshengchanqiyelinxuan=new Shengchanqiyelinxuan();
                    mmshengchanqiyelinxuan.setId(mmid);
                    mmshengchanqiyelinxuan.setSuijilunci(mmsuijilunci);
                    ddService.modify(mmshengchanqiyelinxuan);
                }
            }
            leixing3_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"3").size();
            if(leixing3>leixing3_smplinged){
                smpling();
            }
        }

        int leixing4_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"4").size();
        if(leixing4>leixing4_smplinged){
            List<Map<String,Object>> mmRandomPinzhong=ddService.chouQupinzhong("4");
            if(mmRandomPinzhong.size()>0){
                String mmpinzhongbianhao=mmRandomPinzhong.get(0).get("pinzhongbianhao").toString();
                List<Shengchanqiyelinxuan> mmYaopinlist=ddService.findByPinzhongbianhao(mmpinzhongbianhao);
                for (Shengchanqiyelinxuan mmShengchanqiyelinxuan:mmYaopinlist){
                    String mmid=mmShengchanqiyelinxuan.getId();
                    Shengchanqiyelinxuan mmshengchanqiyelinxuan=new Shengchanqiyelinxuan();
                    mmshengchanqiyelinxuan.setId(mmid);
                    mmshengchanqiyelinxuan.setSuijilunci(mmsuijilunci);
                    ddService.modify(mmshengchanqiyelinxuan);
                }
            }
            leixing4_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"4").size();
            if(leixing4>leixing4_smplinged){
                smpling();
            }
        }

        int leixing5_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"5").size();
        if(leixing5>leixing5_smplinged){
            List<Map<String,Object>> mmRandomPinzhong=ddService.chouQupinzhong("5");
            if(mmRandomPinzhong.size()>0){
                String mmpinzhongbianhao=mmRandomPinzhong.get(0).get("pinzhongbianhao").toString();
                List<Shengchanqiyelinxuan> mmYaopinlist=ddService.findByPinzhongbianhao(mmpinzhongbianhao);
                for (Shengchanqiyelinxuan mmShengchanqiyelinxuan:mmYaopinlist){
                    String mmid=mmShengchanqiyelinxuan.getId();
                    Shengchanqiyelinxuan mmshengchanqiyelinxuan=new Shengchanqiyelinxuan();
                    mmshengchanqiyelinxuan.setId(mmid);
                    mmshengchanqiyelinxuan.setSuijilunci(mmsuijilunci);
                    ddService.modify(mmshengchanqiyelinxuan);
                }
            }
            leixing5_smplinged=ddService.findSmplingedPinguiBySuijilunciAndPinguileibie(mmsuijilunci,"5").size();
            if(leixing5>leixing5_smplinged){
                smpling();
            }
        }


//        int leixing6_smplinged=ddService.findAllBySuijilunciAndPinguileibie(mmsuijilunci,"6").size();
//        if(leixing6>leixing6_smplinged){
//            List<Map<String,Object>> mmRandomPinzhong=ddService.chouQupinzhong("6");
//            if(mmRandomPinzhong.size()>0){
//                String mmpinzhongbianhao=mmRandomPinzhong.get(0).get("pinzhongbianhao").toString();
//                List<Shengchanqiyelinxuan> mmYaopinlist=ddService.findByPinzhongbianhao(mmpinzhongbianhao);
//                for (Shengchanqiyelinxuan mmShengchanqiyelinxuan:mmYaopinlist){
//                    String mmid=mmShengchanqiyelinxuan.getId();
//                    Shengchanqiyelinxuan mmshengchanqiyelinxuan=new Shengchanqiyelinxuan();
//                    mmshengchanqiyelinxuan.setId(mmid);
//                    mmshengchanqiyelinxuan.setSuijilunci(mmsuijilunci);
//                    ddService.modify(mmshengchanqiyelinxuan);
//                }
//            }
//            leixing6_smplinged=ddService.findAllBySuijilunciAndPinguileibie(mmsuijilunci,"6").size();
//            if(leixing6>leixing6_smplinged){
//                smpling();
//            }
//        }


//        if(leixing1_smplinged<leixing1&&leixing2_smplinged<leixing2&&leixing3_smplinged<leixing3&&
//                leixing4_smplinged<leixing4&&leixing5_smplinged<leixing5&&leixing6<leixing6_smplinged){
//            smpling();
//        }

    }

}
